﻿namespace PowerStation.RequestModel.MQTT
{
    /// <summary>
    /// 发送指令模型
    /// </summary>
    public class SwitchModel
    {
        public string useruuid { get; set; } = "0";
        public string commuuid { get; set; } = "0";
        public Instr instr { get; set; }
        public string timeout { get; set; } = "60";

        /// <summary>
        /// 创建模型
        /// </summary>
        /// <param name="cmdName">命令名称,START/STOP开机/关机,ADJPWRP修改功率,AUTO回归自动控制</param>
        /// <param name="param">命令参数,默认为-1,当instr.name为ADJPWRP时,传功率</param>
        public static SwitchModel CreateModel(string cmdName, string param) {
            var m = new SwitchModel();
            m.instr = new Instr();
            m.instr.name = cmdName;
            m.instr.param = new[] {param };
            return m;
        }
        /// <summary>
        /// 创建字符串
        /// </summary>
        /// <param name="cmdName">命令名称,START/STOP开机/关机,ADJPWRP修改功率,AUTO回归自动控制</param>
        /// <param name="param">命令参数,默认为-1,当instr.name为ADJPWRP时,传功率</param>
        /// <returns></returns>
        public static string CreateJson(string cmdName, string param)
        {
            return System.Text.Json.JsonSerializer.Serialize(CreateModel(cmdName,param));
        }
    }

    public class Instr
    {
        public string name { get; set; }
        public string[] param { get; set; }
    }

}
